package com.dingwei.superiordiary.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.mvp.presenter.ModifyNickNamePresenter;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by lihao on 2017/9/19.
 * 修改姓名
 */

public class ModifyNickNameActivity extends BaseActivity implements Contract.ModifyNickNameView {
    ModifyNickNamePresenter modifyNamePresenter = new ModifyNickNamePresenter(this);

    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.et_name)
    EditText etName;


    @Override
    protected int getContentViewId() {
        return R.layout.activity_modify_name;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        tvTitle.setText("修改昵称");
        tvRight.setText("保存");
        etName.setText(getIntent().getStringExtra("nickname"));
    }

    @Override
    protected void initListener() {

    }


    @OnClick({R.id.img_back, R.id.tv_right})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.tv_right:
                modifyNamePresenter.saveName(etName.getText().toString());
                break;
        }
    }

    @Override
    public void saveNickNameSuccess(String nickname) {
        BaseActivity.value.setUserName(nickname);
        intent = new Intent();
        intent.putExtra("nickname", nickname);
        setResult(Activity.RESULT_OK, intent);
        finish();
    }
}
